package com.zbkj.admin.controller.platform;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.AgentConfigDetailResponse;
import com.zbkj.common.result.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.zbkj.service.service.AgentConfigService;
import com.zbkj.common.response.AgentConfigPageDataResponse;

/**
 * 平台代理配置 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/agent/config")
@Api(tags = "平台代理配置") //配合swagger使用

public class AgentConfigController {

    @Autowired
    private AgentConfigService agentConfigService;

    /**
     * 分页显示平台代理配置表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-07-01
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<AgentConfigPageDataResponse>> getList(@Validated AgentConfigSearchRequest request,
                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<AgentConfigPageDataResponse> agentConfigCommonPage = CommonPage.restPage(agentConfigService.getList(request, pageParamRequest));
        return CommonResult.success(agentConfigCommonPage);
    }

    /**
     * 新增平台代理配置表
     * @param agentConfigSaveRequest 新增参数
     * @author dazongzi
     * @since 2025-07-01
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated AgentConfigSaveRequest agentConfigSaveRequest) {
        if(agentConfigService.create(agentConfigSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除代理设置")
    @ApiOperation(value = "批量删除代理设置")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (agentConfigService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 修改平台代理配置表
     * @param agentConfigRequest 修改参数
     * @author dazongzi
     * @since 2025-07-01
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated AgentConfigSaveRequest agentConfigRequest) {
        if (agentConfigService.updatePlatform(agentConfigRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询平台代理配置表信息
     * @param id Integer
     * @author dazongzi
     * @since 2025-07-01
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<AgentConfigDetailResponse> detail(@PathVariable("id") Integer id) {
        return CommonResult.success(agentConfigService.getDetailById(id));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "修改代理设置启用状态")
    @ApiOperation(value = "修改启用状态")
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    public CommonResult<Object> updateStatus(@Validated @RequestBody AgentStatusRequest request) {
        if (agentConfigService.updateStatus(request)) {
            return CommonResult.success("修改成功");
        }
        return CommonResult.failed("修改失败");
    }

}



